/*
 *  Copyright 2009 David Kuhn <david.s.kuhn at gmail.com>.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package com.google.code.teamtools.client.model;

import com.google.gwt.user.client.rpc.IsSerializable;

/**
 *
 * @author David Kuhn <david.s.kuhn at gmail.com>
 */
public abstract class AbstractResource implements IResource, IsSerializable
{
    private Long id;
    private String name;
    private IResourceOwner owner;

    protected AbstractResource()
    {
        // Needs to be here for GWT's RPC mechanism...
    }

    protected AbstractResource(Long id)
    {
        this.id = id;
    }

    protected AbstractResource(Long id, String name)
    {
        this(id);
        setName(name);
    }

    protected AbstractResource(Long id, String name, IResourceOwner owner)
    {
        this(id, name);
        this.owner = owner;
    }

    public IResourceOwner getOwner()
    {
        return owner;
    }

    public void setOwner(IResourceOwner owner)
    {
        this.owner = owner;
    }

    public Long getId()
    {
        return id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }
    
    @Override
    public boolean equals(Object obj)
    {
        if (obj != null && obj instanceof AbstractResource) {
            AbstractResource mobj = (AbstractResource) obj;
            return (getId().equals(mobj.getId()) && 
                    getName().equals(mobj.getName()));
        }
        return super.equals(obj);
    }

    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder("Resource[");
        sb.append("id:" + getId());
        sb.append("|name:" + getName());
        sb.append("|owner:" + getOwner().toString());
        sb.append("]");
        return sb.toString();
    }
}
